package com.bed.lovewithpatientbed.controller;

import com.bed.lovewithpatientbed.pojo.Address;
import com.bed.lovewithpatientbed.pojo.Hospital;
import com.bed.lovewithpatientbed.pojo.Order;
import com.bed.lovewithpatientbed.service.AddressService;
import com.bed.lovewithpatientbed.service.HospitalService;
import com.bed.lovewithpatientbed.service.IOrderService;
import com.bed.lovewithpatientbed.service.StatisticsService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.lang.model.element.NestingKind;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.*;

/**
 * @author Tyl
 * @version 1.0.0
 * @ClassName Statistics.java
 * @Description 统计controller业务模块实现
 * @createTime 2020年10月13日 16:34:00
 */
@Controller
@RequestMapping("statistics")
public class StatisticsController {
  @Resource
  StatisticsService statisticsService;
  @Resource
  HospitalService hospitalService;
  @Resource
  AddressService addressService;
  @Resource
  IOrderService iOrderService;
  /*
  * 按照医院查询租金
  * */
  @RequestMapping("selectRentByHospitalIdDo")
  @ResponseBody
  public Map<String,Object> selectRentByHospitalId(Integer hospitalId){
    Map<String,Object> maps = new HashMap<String, Object>();
    /*每个医院的租金*/
    BigDecimal rentSum = statisticsService.selectRentByHospitalId(hospitalId);
    /*查出所有医院*/
    List<Hospital> hospitalList = hospitalService.getAll();
    maps.put("A",hospitalList);
    maps.put("rentSum",rentSum);
    return maps;
  }
  @RequestMapping("selectListDo")
  @ResponseBody
  public Map<String,Object> selectList(String sequence,String province){
    Map<String,Object> maps = new HashMap<>();
    /*查出所有医院*/
    List<Hospital> hospitalLists = hospitalService.selectByExample(sequence,province);
    /*把所有医院的名字封装到集合中*/
    List<String> hospitalNames = new ArrayList<>();
    for (Hospital hospital :hospitalLists) {
      hospitalNames.add(hospital.getHospitalName());
    }
    /*把所有医院的租金封装到集合中*/
    List<BigDecimal> hospitalRents = new ArrayList<>();
    for(Hospital hospital :hospitalLists){
      hospitalRents.add(hospital.getHospitalRent());
    }
    maps.put("hospitalName",hospitalNames);
    maps.put("hospitalList",hospitalLists);
    maps.put("hospitalRent",hospitalRents);
    return maps;
  }
  /**
   * @description 把地址信息传到页面
   * @author tyl
   * @updateTime 2020/10/14 16:00
   */
  @RequestMapping("addressList")
  @ResponseBody
  public Map<String,Object> addressList(){
    Map<String,Object> maps = new HashMap<String, Object>();
    /*查出所有地址*/
    List<Address> addressList = addressService.selectByDistinct();
    maps.put("addressList",addressList);
    return maps;
  }
  /**
   * @description 通过订单时间和医院查询
   * @author tyl
   * @updateTime 2020/10/16 16:44
   * @param start:开始时间;end:结束时间;hospitalId:医院id
   */
  @RequestMapping("selectByTime")
  @ResponseBody
  public Map<String,Object> selectByTime(String start,String end,Integer hospitalId) throws ParseException {
    System.out.println(start+"```````````````"+end);
    List<Order> orderList = iOrderService.selecOrderNumByHospitalId(start,end,hospitalId);
    System.out.println(orderList);
    Map<String, Object> map = new HashMap<>();
    map.put("orderList",orderList);
    return map;
  }
  @RequestMapping("selectByProvinceList")
  @ResponseBody
  public List<Integer> selectByProvinceList(@RequestParam(value = "ids", required = true)List<String> provinceList){
    System.out.println(provinceList);
     List<Integer> hospitalNum = hospitalService.selectByProvinces(provinceList);
     return hospitalNum;
  }
}
